<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>我的任务</title>
<script src="MyDatePicker/WdatePicker.js"></script>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="jquery-easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="jquery-easyui/themes/icon.css">
<script type="text/javascript" src="jquery-easyui/jquery.min.js"></script>
<script type="text/javascript" src="jquery-easyui/jquery.easyui.min.js"></script>
</head>
<body>
<ol class="breadcrumb" style="margin-bottom:5px;">
	<li><a href="#">任务系统</a></li>
	<li class="active">我的任务</li>
</ol>
<div class = "container-fluid" style="padding-left:10px;padding-right:10px;">
<table id="t1" toolbar="#tb1" class="easyui-datagrid" style="width:auto; height:500px;"  striped="true" ></table>
</div>
<div id="help" hidden="true">${Emp.p_id}</div>
<!-- 3.动态查询 div -->
<div id="tb1" style="padding:3px">
	<span>汇报内容:</span>
	<input id="missionReport" style="line-height:26px;border:1px solid #ccc">
	<span>审核结果:</span>
	<input id="missioncheck" style="line-height:26px;border:1px solid #ccc">
	<span>任务状态:</span>
	  	<select name="missionState" id="missionState" style="width: 100px;height:30px">
             <option value="" selected="selected">任务状态</option>
             <option value="下发" >下发</option>
             <option value="已反馈" >已汇报</option>
             <option value="已完成" >已完成</option>
             <option value="已失败" >已取消</option> 
         </select> 
	<a  class="easyui-linkbutton" plain="true" iconCls="icon-search" onclick="doSearch()">搜索</a>
</div>
<!-- 1.反馈弹出框div -->
 <div id="feedback" class="easyui-dialog"  title="任务反馈"  closed="true" style="width:400px;height:450px"  data-options="iconCls:'icon-save',modal:true">   
	<form id="feedback1" style="padding:10px 20px 10px 40px;">
		<p>任务编号: <input type="text" class="form-control" id="m_id" name="m_id" readonly="readonly" placeholder="任务编号" ></p>
		<p>任务名称: <input type="text" class="form-control" id="m_name" name="m_name" readonly="readonly"  placeholder="任务名称" ></p>
		<p>任务内容: <textarea  class="form-control" id="m_content" name="m_content" readonly="readonly" placeholder="任务内容" ></textarea></p>
		<p>截止时间: <input type="text" class="form-control" id="m_end_date" name="m_end_date" readonly="readonly"  onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})" placeholder="截止时间"  /></p>
		<p>任务反馈: <textarea  class="form-control" id="m_report" name="m_report" placeholder="汇报任务" ></textarea></p>
		<div style="padding:5px;text-align:center;">
			<a onclick = "feedback1()" class="easyui-linkbutton" icon="icon-ok">反馈</a>
			<a onclick="cancel1()" class="easyui-linkbutton" icon="icon-cancel">取消</a>
		</div>
	</form>
</div> 
<!-- 2.审批div -->
<div id="check" class="easyui-dialog"  title="任务审核"  closed="true" style="width:300px;height:500px"   
        data-options="iconCls:'icon-save',modal:true">   
	<form id="shenhe1" style="padding:10px 20px 10px 40px;">
		<p>任务编号: <input type="text" class="form-control" id="m_id1" name="m_id"  readonly="readonly" placeholder="任务编号" ></p>
		<p>任务名称: <input type="text" class="form-control" id="m_name1" name="m_name" readonly="readonly"  placeholder="任务名称" ></p>
		<p>任务内容: <textarea  class="form-control" id="m_content1" name="m_content" readonly="readonly" placeholder="任务内容" ></textarea></p>
		<p>截止时间: <input type="text" class="form-control" id="m_end_date1"  name="m_end_date" readonly="readonly" onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})" placeholder="截止时间"  /></p>
		<p>汇报内容: <textarea  class="form-control" id="m_report1" name="m_report" readonly="readonly" placeholder="任务汇报" ></textarea></p>
		<p>审核结果: <textarea  class="form-control" id="m_check_result1" name="m_check_result" placeholder="任务审核" ></textarea></p>
		<div style="padding:5px;text-align:center;">
			<a onclick ="check1()" class="easyui-linkbutton" icon="icon-ok">审核</a>
			<a onclick="cancel2()" class="easyui-linkbutton" icon="icon-cancel">取消</a>
		</div>
	</form>
</div> 
<script type="text/javascript">
var pos=$('#help').html();
console.log(pos);
$('#t1').datagrid({    
    url:'DeliverMissionToList.do', 
    pagination:true,
    fitColumns:true,
    pageList:[2,4,6,8,10],
    columns:[[  
        {field:'m_id',title:'任务编号',width:100,align:'center'}, 
        {field:'m_name',title:'任务名称',width:100,align:'center'}, 
        {field:'m_content',title:'任务内容',width:100,align:'center'},
        {field:'e_id',title:'执行人编号',width:100,align:'center'}, 
        {field:'e_name',title:'执行人',width:100,align:'center'},   
        {field:'m_end_date',title:'任务截止日期',width:100,align:'center'},
        {field:'m_report',title:'汇报内容',width:100,align:'center'},
        {field:'m_report_date',title:'任务汇报时间',width:100,align:'center'},
        {field:'m_check_date',title:'审核时间',width:100,align:'center'},
        {field:'m_check_result',title:'审核结果',width:100,align:'center'},
        {field:'d_state',title:'执行状态',width:100,align:'center'},
        {field:'link',title:'操作',width:150,align:'center',formatter:function(value,row,rowIndex){
        	if(pos=='P003'){
        		if(row.d_state=='下发'){
            		return '<button  onclick="return feedback(\''+row.m_id+'\');">反馈</button> <button  onclick="return abandon(\''+row.m_id+'\');" >撤销</button>';
        		}	
        	}else {
        		if(row.d_state=='已汇报'){
        			return '<button  onclick="return check(\''+row.m_id+'\');">审核</button> ';	
        		}else if(row.d_state=='已汇报'){
        			return '<button  onclick="return toinfo(\''+row.m_id+'\');">详情</button> ';
        		}
        	}
        }},
    ]] ,
    success: function (data) {
    	console.log("row.d_state="+row.d_state);
    	console.log(data);
    },
}); 
function feedback(m_id){
	$('#feedback').dialog('open');
	$.ajax({
		type: "get",
		url:"feedbackMission.do?m_id="+m_id,
		dataType:'json',
		success: function (data) {
	       	$('#m_id').val(data.m_id);
	    	$('#m_name').val(data.m_name);
	    	$('#m_content').val(data.m_content);
	    	$('#m_end_date').val(data.m_end_date);
	    	$('#m_report').val(data.m_report);
		}
	});
	return false;
}
function feedback1(){
	$.ajax({
        type: "post",
        url:"MissionFeedback.do",
        dataType:'json',
        data:$('#feedback1').serialize(),
        error: function(request) {
            alert("Connection error");
        },
        success: function(data) {
        	$.messager.alert('消息',data.msg,'info',function(){
        		window.location.href="DeliverMission.jsp";
        	});
        }
    });
	return false;
}	
function check(m_id){
	$('#check').window('open');
	$.ajax({
		type: "get",
		url: "checkMission.do?m_id="+m_id,
		dataType:'json',
		success: function (data) {
	       	$('#m_id1').val(data.m_id);
	    	$('#m_name1').val(data.m_name);
	    	$('#m_content1').val(data.m_content);
	    	$('#m_end_date1').val(data.m_end_date);
	    	$('#m_report1').val(data.m_report);
	    	$('#m_check_result1').val(data.m_check_result);
		}
	});
}
function check1(){
	$.ajax({
        type: "POST",
        url:"MissionCheck.do",
        dataType:'json',
        data:$('#shenhe1').serialize(),
        error: function(request) {
            alert("Connection error");
        },
        success: function(data) {
        	console.log(data);
        	$.messager.alert('消息',data.msg,'info',function(){
        		window.location.href="DeliverMission.jsp";
        	});
        }
    });
	return false;
}
function cancel1(){
	$('#feedback').dialog('close');
}	
function cancel2(){
	$('#check').dialog('close');
}	
function abandon(m_id){
	$.ajax({
		url: "abandonMission.do?m_id="+m_id,
		dataType:'json',
		success: function (data) {
       		$.messager.alert('消息',data.msg,'info',function(){
   				window.location.href="DeliverMission.jsp";
   			});
		}
	});
}

function doSearch(){
	$('#t1').datagrid('load',{
		//m_id:$('#missionId').val(),
		//m_name:$('#missionName').val(),
		m_report:$('#missionReport').val(),
		m_check_result:$('#missioncheck').val(),
		d_state:$('#missionState').val()
	});
}
function toInfo(m_id){
	
}
</script>
</body>
</html>